package com.redstar.HappyRefresh.pojo;

import com.baomidou.mybatisplus.annotation.*;
import com.redstar.HappyRefresh.config.QiNiuConfig;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.util.ObjectUtils;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.*;

@Data
@EqualsAndHashCode(callSuper = false)
public class Video implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    //逻辑删除，0未删除，1删除，默认为0
    @TableLogic
    private Boolean isDeleted;

    @TableField(fill = FieldFill.INSERT)
    private Date gmtCreated;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date gmtUpdated;

    // 视频标识，用于精准搜索视频，字符串"YV"+UUID
    private String yv;

    @NotBlank(message = "标题不能为空")
    private String title;

    // 视频简介
    private String description;

    // 文件路径
    private Long url;

    private Long userId;

    // 封面
    private Long cover;

    // 公开或私密, 0公开, 1私密, 默认为0
    private Boolean open;

    // 审核状态：通过, 未通过, 审核中
    private Integer auditStatus;

    // 审核状态的消息
    private String msg;

    // 审核快慢状态，0慢速, 1快速
    private Boolean auditQueueStatus;

    // 点赞数
    private Long startCount;

    // 分享数
    private Long shareCount;

    // 浏览次数
    private Long historyCount;

    // 收藏次数
    private Long favoritesCount;

    // 视频时长
    private String duration;

    // 文件的mimeType，文件的性质
    @TableField(exist = false)
    private String videoType;

    // 视频标签
    private String labelNames;

    private Long typeId;

    // 关联的用户
    @TableField(exist = false)
    private UserVO user;

    // 关联分类名称
    @TableField(exist = false)
    private String typeName;

    // 是否点赞
    @TableField(exist = false)
    private Boolean start;

    // 是否收藏
    @TableField(exist = false)
    private Boolean favorites;

    // 是否关注，自己关注自己？？
    @TableField(exist = false)
    private Boolean follow;

    // 用户昵称
    @TableField(exist = false)
    private String userName;

    // 审核状态名称
    @TableField(exist = false)
    private String auditStateName;

    // 是否公开
    @TableField(exist = false)
    private String openName;

    public List<String> buildLabel(){
        if (ObjectUtils.isEmpty(labelNames)) {
            return new ArrayList<>();
        }
        String[] labelSplit = labelNames.split("，");
        return Arrays.asList(labelSplit);
    }

    public String buildVideoUrl(){
        return QiNiuConfig.CNAME + "/" + url;
    }

    public String buildCoverUrl(){
        return QiNiuConfig.CNAME + "/" + cover;
    }


}

